//
//  GXBannerFromModel_Two.m
//  Gxj
//
//  Created by tcwx on 2017/9/25.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "GXBannerFromModel_Two.h"

NSString *const kGXModel_TwoTitle            = @"title";
NSString *const kGXModel_TwoUrl              = @"url";
NSString *const kGXModel_TwoImsrc            = @"imgsrc";

@implementation GXBannerFromModel_Two

@synthesize title  = _title;
@synthesize url    = _url;
@synthesize imgsrc = _imgsrc;

+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

// 初始化
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    if (self && [dict isKindOfClass:[NSDictionary class]])
    {
        _title  = [self checkNilObjectForKey:kGXModel_TwoTitle       fromDictionary:dict];
        _url    = [self checkNilObjectForKey:kGXModel_TwoUrl         fromDictionary:dict];
        _imgsrc = [self checkNilObjectForKey:kGXModel_TwoImsrc       fromDictionary:dict];
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:_title         forKey:kGXModel_TwoTitle];
    [mutableDict setValue:_url           forKey:kGXModel_TwoUrl];
    [mutableDict setValue:_imgsrc        forKey:kGXModel_TwoImsrc];
    
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (id)checkNilObjectForKey:(id)key fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:key];
    return [object isKindOfClass:[NSNull class]] ? nil : object;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@",[self dictionaryRepresentation]];
}


@end
